package com.feini.ktv.svc.controller.pm;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.feini.ktv.svc.entity.pm.PmOffer;
import com.feini.ktv.svc.service.pm.IPmOfferService;
import com.podara.skeleton.controller.SkeletonController;
import com.podara.skeleton.log.annotation.LogLogger;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jiangzr
 * @since 2021-04-09
 */
@LogLogger
@RestController
public class PmOfferController implements SkeletonController {

    @Autowired
    private IPmOfferService pmOfferService;

    @GetMapping("/offerList/{offerType}")
    public List<PmOffer> offerList(@PathVariable("offerType") String offerType) {
        QueryWrapper<PmOffer> offer = new QueryWrapper<PmOffer>();
        if (StringUtils.equals(offerType, "first")) {
            offerType = "1";
        } else if (StringUtils.equals(offerType, "second")) {
            offerType = "2";
        } else if (StringUtils.equals(offerType, "third")) {
            offerType = "3";
        } else {
            offerType = "5";
        }
        offer.eq("offer_type", offerType);
        List<PmOffer> offerList = this.pmOfferService.list(offer);
        return offerList;
    }

    @GetMapping("/queryOfferLikeName/{offerName}")
    public List<PmOffer> queryOfferLikeName(@PathVariable("offerName") String offerName) {
        QueryWrapper<PmOffer> offer = new QueryWrapper<PmOffer>();
        offer.eq("offer_name", offerName);
        List<PmOffer> offerList = this.pmOfferService.list(offer);
        return offerList;
    }

}

